<?php

/**
 * Chat module
 *
 * @author     Mon Zafra <monzee at gmail>
 * @copyright  (c)2009 Mon Zafra
 * @category   Mz
 * @package    modules
 * @subpackage chat
 * @license    http://mz-project.googlecode.com/svn/trunk/LICENSE    MIT License
 * @version    SVN: $Id: Bootstrap.php 12 2009-02-28 13:39:31Z monzee $
 */
class Chat_Bootstrap extends Mz_Module_Bootstrap
{
    public function init()
    {
        /*
         * todo list:
         *   - cookies
         *   - edit/delete by cookie/ip
         *   - ajaxify
         *   - refresh
         *   - email vs. http:// in url
         *   - large mode with pagination
         *   - incorporate user module (when it's done)
         * 
         */
    }

    /**
     * @var Chat_Chatbox
     */
    protected $_model;

    /**
     *
     * @return Chat_Chatbox
     */
    public function getModel()
    {
        if (null === $this->_model) {
            $this->_model = new Chat_Chatbox();
        }
        return $this->_model;
    }

    /**
     *
     * @param int  $num
     * @param bool $ascending
     * @return array
     */
    public function getLast($num = 5, $ascending = false)
    {
        $model = $this->getModel();

        $res = $model->getRecentRows($num);
        if (false === $res || null === $res) {
            // table does not exist
            return array();
        }

        $rows = $res->fetchAll();
        return $ascending ? array_reverse($rows) : $rows;
    }

}
